﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Lyon.WinForm
{
    /// <summary>
    /// 等待框。
    /// </summary>
    public class WaitBox
    {
        static public void Show(IWin32Window owner, Callback action, Callback finished, Callback abort)
        {
            Show(owner, "加载中...", action, finished, abort);
        }
        static public void Show(IWin32Window owner, string title, Callback action, Callback finished, Callback abort)
        {
            if (owner is Control && ((Control)owner).Parent != null)
            {
                WaitPanel repeatPanel = new WaitPanel(action, finished, abort);
                repeatPanel.Context = title;
                repeatPanel.Text = title;
                repeatPanel.DoAction();
                repeatPanel.ShowDialog(((Control)owner).Parent);
            }
            else
            {
                WaitForm repeatForm = new WaitForm(action, finished, abort);
                repeatForm.Context = title;
                repeatForm.Text = title;
                repeatForm.DoAction();
                repeatForm.Show(owner);
            }
        }


        static public void ShowDialog(IWin32Window owner, Callback action, Callback finished, Callback abort)
        {
            ShowDialog(owner, "加载中...", action, finished, abort);
        }
        static public void ShowDialog(IWin32Window owner, string title, Callback action, Callback finished, Callback abort)
        {
            WaitForm repeatForm = new WaitForm(action, finished, abort);
            repeatForm.Context = title;
            repeatForm.Text = title;
            repeatForm.Load += new EventHandler(delegate(object sender, EventArgs e)
            {
                repeatForm.DoAction();
            });
            repeatForm.ShowDialog(owner);
        }
    }
}
